package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.LbsTerminal;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.LbsTerminalDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2021-07-05 11:06:21
 */
public class LbsTerminalConverts {

    private static Logger LOG = LoggerFactory.getLogger(LbsTerminalConverts.class);

    public static List<LbsTerminalDTO> convert(List<LbsTerminal> lbsTerminalList) {
        if (CollectionUtils.isEmpty(lbsTerminalList)) {
            return Collections.EMPTY_LIST;
        }

        List<LbsTerminalDTO> lbsTerminalListResult = Lists.newArrayList();
        for (LbsTerminal lbsTerminal : lbsTerminalList) {
            lbsTerminalListResult.add(convert(lbsTerminal));
        }
        return lbsTerminalListResult;
    }

    public static LbsTerminalDTO convert(LbsTerminal lbsTerminal) {
        try {
            return BeanUtils.copy(lbsTerminal, LbsTerminalDTO.class);
        } catch (Exception e) {
            LOG.error("LbsTerminal到LbsTerminalDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "LbsTerminal到LbsTerminalDTO转换失败", e);
        }
    }

    public static LbsTerminal convert(LbsTerminalDTO lbsTerminalDTO) {
        try {
            return BeanUtils.copy(lbsTerminalDTO, LbsTerminal.class);
        } catch (Exception e) {
            LOG.error("LbsTerminalDTO到LbsTerminal转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "LbsTerminalDTO到LbsTerminal转换失败", e);
        }
    }
}